﻿var loadingDiv;
$(initPage);
function initPage() {
	loadingDiv = $("<div style='display:none'><div style='width:100%;z-index:101;height:100%;background-color:#ccc;filter:alpha(Opacity=20);-moz-opacity:0.2;opacity: 0.2;position:absolute;top:0px;left:0px;'></div></div>").appendTo(jQuery(document.body));
	$("<div style='position:absolute;z-index:9999999;border:1px solid #eee;padding:20px 0 0 20px;width:390px;height:48px'/>").css({left:document.body.clientWidth/2-200,top:document.body.clientHeight/2-80}).append("<img width='200' height='15' src='" + BASE_PATH + "themes/comm/images/loading.gif' align='absmiddle'/>&nbsp;<font style='font-size:18px;color:#f30'>后台正在处理中……</font>").appendTo(loadingDiv);
	
	$("#passed").click(function() {
		submitObj(true);
	});
	
	$("#reject").click(function() {
		submitObj(false);
	});
	$("#cancel").click(function() {
		cancelObj();
	});
	
}

function submitObj(passed) {
	var taskId = $("#taskId").val();
	if($.validInput("comment", "审批意见", false, "", 500)){
		return false;
	}
//	$("#passed,#reject,#cancel").attr("disabled", true);
	loadingDiv.show();
	$.post("m/submit_task/deal", {
		taskId:taskId,
		comment:$("#comment").val(),
		passed:passed
	}, function(data) {
		if ($.checkErrorMsg(data) ) {
//			alert("操作成功！");
			location.reload();
		} else {
			loadingDiv.hide();
		}
	}, "json");
}

function cancelObj() {
	$("#passed,#reject,#cancel").attr("disabled", true);
	var taskId = $("#taskId").val();
	var comment = $("#comment").val();
	$.post("m/submit_task/cancel", {
		taskId:taskId,
		comment:comment
	}, function(data) {
		if ($.checkErrorMsg(data) ) {
			alert("操作成功！");
			location.reload();
		} else {
			$("#passed,#reject,#cancel").attr("disabled",false);
		}
	}, "json");
}